// miniprogram/pages/hz/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    background: ['https://sd.offcn.com/zg/wximg/2021/jdwz/jdwzhz-img/banner_1.png', 'https://sd.offcn.com/zg/wximg/2021/jdwz/jdwzhz-img/banner_2.png'],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 4000,
    duration: 500,
    navlist: [{
        src: 'https://sd.offcn.com/zg/wximg/2021/jdwz/jdwzhz-img/icon_1.png',
        title: '成绩查询',
        out: 'out'
      },
      {
        src: 'https://sd.offcn.com/zg/wximg/2021/jdwz/jdwzhz-img/icon_2.png',
        title: '晒分查排名',
        out: 'shaifen'
      },
      {
        src: 'https://sd.offcn.com/zg/wximg/2021/jdwz/jdwzhz-img/icon_3.png',
        title: '面试起航峰会',
        out: 'mianshi'
      },
      {
        src: 'https://sd.offcn.com/zg/wximg/2021/jdwz/jdwzhz-img/icon_4.png',
        title: '1V1面试评测',
        out: 'yvy'
      },
      {
        src: 'https://sd.offcn.com/zg/wximg/2021/jdwz/jdwzhz-img/icon_5.png',
        title: '历年答题范例',
        out: 'fanli'
      },
      {
        src: 'https://sd.offcn.com/zg/wximg/2021/jdwz/jdwzhz-img/icon_6.png',
        title: '面试题本领取',
        out: 'mst'
      },
      {
        src: 'https://sd.offcn.com/zg/wximg/2021/jdwz/jdwzhz-img/icon_7.png',
        title: '专业科目问答',
        out: 'bwbd'
      },
      {
        src: 'https://sd.offcn.com/zg/wximg/2021/jdwz/jdwzhz-img/icon_8.png',
        title: '人工咨询',
        out: 'xiaoneng'
      },

    ]
  },
  out: function () {
    var that = this;
    if (that.data.ifPhone) {
      wx.navigateTo({
        url: '../out/out',
      })
    } else {
      that.setData({
        fixed: 1
      })
    }

  },
  shaifen: function () {
    var that = this;
    if (that.data.ifPhone) {
      wx.navigateToMiniProgram({
        appId: 'wxd8b655bb6bc8e7dc', //模考appid
        path: 'pages/index/index?q=https%3A%2F%2F81jdwz.offcn.com%2Fminiprogram%2Fwxd8b655bb6bc8e7dc%2F%3Fsid%3D76845a1bc8210e5207b123a36d76c0d8%26formid%3D92882%26owner%3D29241', //模考
        envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
        success(res) {
          console.log('打开成功！')
        }
      })
    } else {
      that.setData({
        fixed: 1
      })
    }
  },
  mianshi: function () {

    var that = this;
    if (that.data.ifPhone) {
      wx.navigateToMiniProgram({
        appId: 'wxca86930ec3e80717', //模考appid
        path: 'page/course/details?id=327539&scode=', //模考
        envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
        success(res) {
          console.log('打开成功！')
        }
      })
    } else {
      that.setData({
        fixed: 1
      })
    }
  },
  yvy: function () {

    var that = this;
    if (that.data.ifPhone) {
      wx.navigateTo({
        url: '../yvy/yvy',
      })
    } else {
      that.setData({
        fixed: 1
      })
    }
  },
  fanli: function () {


    var that = this;
    if (that.data.ifPhone) {
      wx.navigateToMiniProgram({
        appId: 'wxca86930ec3e80717', //模考appid
        path: 'page/course/details?id=330020&scode=', //模考
        envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
        success(res) {
          console.log('打开成功！')
        }
      })
    } else {
      that.setData({
        fixed: 1
      })
    }
  },
  mst: function () {

    var that = this;
    if (that.data.ifPhone) {
      wx.navigateTo({
        url: '../mst/mst',
      })
    } else {
      that.setData({
        fixed: 1
      })
    }
  },
  bwbd: function () {

    var that = this;
    if (that.data.ifPhone) {
      wx.navigateTo({
        url: '../bwbd/bwbd',
      })
    } else {
      that.setData({
        fixed: 1
      })
    }
  },
  xiaoneng: function () {

    var that = this;
    if (that.data.ifPhone) {
      wx.navigateTo({
        url: '../../xiaoneng/xiaoneng',
      })
    } else {
      that.setData({
        fixed: 1
      })
    }
  },

  getPhoneNumber(e) {
    var that = this;
    var fenxiao = that.data.area;
    var geneal = that.data.geneal;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      wx.setStorageSync('jdwzhzphone', res.result)
      console.log(res.result)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/register?actid=40430&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: fenxiao,
          geneal: geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          that.setData({
            ifPhone: 1,
            fixed: !1
          })
        }
      })

      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 29,
          mobile: res.result,
          areaCode: that.data.area,
          agent: that.data.geneal,
          pageId: that.data.page
        },
        success: res => {
          console.log(res);
        }
      })
    }).catch(err => {
      console.error(err);
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }

    var phone = wx.getStorageSync('jdwzhzphone')
    if (phone) {
      that.setData({
        ifPhone: 1
      })
    } else {
      that.setData({
        ifPhone: !1
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

 /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
   
    return {
      title: '军队文职备考',
      path: '/pages/hz/index/index',
    }

  }
})